#include "head.hpp"
#include "IMySqlApi.h"
#include "IHttpLink.h"

void testConfig();

void testHttplib();

int main() {
    testConfig();
    testHttplib();
    return 0;
}

void testHttplib() {
    httplib::Server server;
    ConfigFile cf;
    server.set_base_dir(cf.GetString("wwwroot").c_str());
    
    TeacherLink* tea = new TeacherLink();
    server.Post(R"(/tea)",tea->Insert);
    server.Delete(R"(/tea/(\d+))",tea->Delete);
    server.Put(R"(/tea/(\d+))",tea->Put);
    server.Get(R"(/tea)",tea->Getall);
    server.Get(R"(/tea/(\d+))",tea->Getone);
    bool ret = server.listen(cf.GetString("listenIp").c_str(),cf.GetInt("listenPort",19998));
    if(ret == false) cout << "SSS" << endl;
}

void testConfig() {
    ConfigFile cf;
    cf.read();

    cout << "[MySQL]" << endl;
    cout << cf.GetString("host") << endl;
    cout << cf.GetInt("port",3306) << endl;
    cout << cf.GetString("password") << endl;
    cout << cf.GetString("name") << endl;
    cout << cf.GetString("user") << endl;

    cout << "\n[NetWork]" << endl;
    cout << cf.GetString("listenIp") << endl;
    cout << cf.GetInt("listenPort",19998) << endl;

    cout << "\n[WWW]" << endl;
    cout << cf.GetString("wwwroot") << endl;
}
